package com.jwthhealth_pub.guardian.view;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.base.BaseActivity;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.jwthhealth_pub.guardian.adapter.FootviewAdapter;
import com.jwthhealth_pub.guardian.bean.GuardianBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.jwthhealth_pub.common.LogUtil.makeLogTag;

/**
 * 查看监护人
 * Created by yang on 2017/12/19.
 *
 */

public class DetailsGuardianActivity extends BaseActivity implements FootviewAdapter.Callback{

    private final String TAG = makeLogTag(DetailsGuardianActivity.class);

    @BindView(R.id.title_layout)
    TitleLayout titleLayout;
    @BindView(R.id.listview_guardianforme)
    ListView listview_guardianforme;
    @BindView(R.id.listview_youforguardian)
    ListView listview_youforguardian;
    @BindView(R.id.tv_guardian_other)
    TextView tv_guardian_other;
    @BindView(R.id.tv_guardian_me)
    TextView tv_guardian_me;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detailsguardian);
        ButterKnife.bind(this);
        GuardianMeData();
        GuardianOtherData();
    }
    //这是监护您的人
 public void  GuardianMeData(){
     ArrayList<GuardianBean> GuardianList_me = new ArrayList<GuardianBean>();
     for (int i = 0; i < 5; i++) {
         GuardianBean bean = new GuardianBean();
         bean.name=("王二小" + i);
         bean.mobile=("137118987" + i );
         GuardianList_me.add(bean);
     }
     FootviewAdapter mFootviewAdapter_me = new FootviewAdapter(this, listview_guardianforme,this);
     listview_guardianforme.setAdapter(mFootviewAdapter_me);
     mFootviewAdapter_me.setAdapterData(GuardianList_me);

 }

    //您要监护的人
    public void  GuardianOtherData(){
        ArrayList<GuardianBean> GuardianList_other = new ArrayList<GuardianBean>();
        for (int i = 0; i < 5; i++) {
            GuardianBean bean = new GuardianBean();
            bean.name=("郑明红" + i);
            bean.mobile=("137158987" + i );
            GuardianList_other.add(bean);
        }
        FootviewAdapter mFootviewAdapter_other = new FootviewAdapter(this, listview_youforguardian,this);
        listview_youforguardian.setAdapter(mFootviewAdapter_other);
        mFootviewAdapter_other.setAdapterData(GuardianList_other);
    }

    //您要监护的人的点击事件
    @OnClick(R.id.tv_guardian_other)
    public void  guardian_otherClick(){
        startActivity(new Intent(DetailsGuardianActivity.this,AddGuardianActivity.class));
    }
    //监护您的人的点击事件
    @OnClick(R.id.tv_guardian_me)
    public void  guardian_meClick(){
        startActivity(new Intent(DetailsGuardianActivity.this,AddGuardianActivity.class));
    }

    protected void title() {
        titleLayout.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }
  //这是解除监护的回调
    @Override
    public void click(View v) {
        showAlertDialog();
    }

    //这是解除监护人的弹出框
    private void showAlertDialog() {

        final AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setView(LayoutInflater.from(this).inflate(R.layout.alert_show_delete_guardian, null));
        dialog.show();
        dialog.getWindow().setContentView(R.layout.alert_show_delete_guardian);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); //设置对话框背景透明 ，对于AlertDialog 就不管用了
        TextView btnPositive = (TextView) dialog.findViewById(R.id.btn_ok);
        TextView cancelPositive = (TextView) dialog.findViewById(R.id.btn_cancel);
        btnPositive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        cancelPositive.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
    }
}
